home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / cenvid.zip / MOUSE.BAT < prev    next >
DOS Batch File  |  1993-04-13  |  3KB  |  107 lines

  1. @echo off
  2. REM *************************************************************************
  3. REM *** Mouse.bat - Display mouse information.  This is an example of     ***
  4. REM ***             using the CEnvi interrupt() function.  The            ***
  5. REM ***             functions will make frequent use of a mouse           ***
  6. REM ***             structure as follows:                                 ***
  7. REM ***                 Col      - mouse column on screen                 ***
  8. REM ***                 Row      - mouse row on screen                    ***
  9. REM ***                 Left     - True if left button down, else False   ***
  10. REM ***                 Middle   - True if middle button down, else False ***
  11. REM ***                 Right    - True if right button down, else False  ***
  12. REM *************************************************************************
  13. cenvi %0.bat
  14. GOTO CENVI_EXIT
  15.  
  16. main()
  17. {
  18.    if ( !InitializeMouse() ) {
  19.       printf("I cannot find a mouse!\a\n")
  20.    } else {
  21.       printf("Displaying mouse status until you press any key:\n")
  22.       printf("Col\tRow\tLeft\tMiddle\tRight\n")
  23.       FlushKeyboard();
  24.       DisplayMouse()
  25.       OldMouse.Row = -1    // force first comparison to be not equal
  26.       while( !kbhit() ) {
  27.          GetMouseState(Mouse)
  28.          if ( Mouse != OldMouse ) {
  29.             // mouse state has changed, and so display new state
  30.             HideMouse()       // must be hidden while screen is changed
  31.             printf("\r%d\t%d\t%s\t%s\t%s",
  32.                    Mouse.Col, Mouse.Row,
  33.                    Mouse.Left ? "DOWN" : "UP  ",
  34.                    Mouse.Middle ? "DOWN" : "UP  ",
  35.                    Mouse.Right ? "DOWN" : "UP  " );
  36.             DisplayMouse()    // must be hidden while screen is changed
  37.             OldMouse = Mouse
  38.          }
  39.       }
  40.       ResetMouse()
  41.       FlushKeyboard();
  42.       printf("\n")
  43.    }
  44. }
  45.  
  46.  
  47. FlushKeyboard()
  48. {
  49.    while( kbhit() )
  50.       getch()
  51. }
  52.  
  53. #define  MOUSE_INTERRUPT      0x33
  54. #define  DRIVER_INSTALLED     0xFFFF
  55. #define  RESET_MOUSE_DRIVER   0
  56. #define  GET_MOUSE_STATE      3
  57. #define  HIDE_MOUSE           2
  58. #define  DISPLAY_MOUSE        1
  59. #define  LEFT_BUTTON_MASK     0x0001
  60. #define  MIDDLE_BUTTON_MASK   0x0004
  61. #define  RIGHT_BUTTON_MASK    0x0002
  62.  
  63. InitializeMouse()
  64. {
  65.    // determine if mouse exists be calling function to see if mouse driver exists
  66.    // and then checking how many buttons it has.  If zero buttons then no mouse.
  67.    reg.ax = RESET_MOUSE_DRIVER
  68.    interrupt(MOUSE_INTERRUPT,reg)
  69.    if ( DRIVER_INSTALLED != reg.ax )
  70.       // Error, no mouse driver installed
  71.       return(False)
  72.    if ( 0 == reg.bx )
  73.       // No buttons means no mouse
  74.       return(False)
  75.    return(True)
  76. }
  77.  
  78. ResetMouse()
  79. {
  80.    InitializeMouse()
  81. }
  82.  
  83. GetMouseState(m)
  84. {
  85.    reg.ax = GET_MOUSE_STATE
  86.    interrupt(MOUSE_INTERRUPT,reg)
  87.    m.Col = (reg.cx >> 3) + 1
  88.    m.Row = (reg.dx >> 3) + 1
  89.    m.Left = (reg.bx & LEFT_BUTTON_MASK) ? True : False
  90.    m.Middle = (reg.bx & MIDDLE_BUTTON_MASK) ? True : False
  91.    m.Right = (reg.bx & RIGHT_BUTTON_MASK) ? True : False
  92. }
  93.  
  94. HideMouse()
  95. {
  96.    reg.ax = HIDE_MOUSE
  97.    interrupt(MOUSE_INTERRUPT,reg)
  98. }
  99.  
  100. DisplayMouse()
  101. {
  102.    reg.ax = DISPLAY_MOUSE
  103.    interrupt(MOUSE_INTERRUPT,reg)
  104. }
  105.  
  106. :CENVI_EXIT
  107.